home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
PROGRAMR
/
OLE2BOOK.ZIP
/
BASICS.ZIP
/
CLASSLIB
/
CCLIENT.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-07
|
17KB
|
710 lines
/*
* CCLIENT.CPP
* Sample Code Class Libraries
*
* Implementation of the CClient class that handles an SDI or MDI
* client area window.
*
* Copyright (c)1993 Microsoft Corporation, All Rights Reserved
*
* Kraig Brockschmidt, Software Design Engineer
* Microsoft Systems Developer Relations
*
* Internet : kraigb@microsoft.com
* Compuserve: >INTERNET:kraigb@microsoft.com
*/
#include <windows.h>
#include "classlib.h"
/*
* CClient::CClient
* CClient::~CClient
*
* Constructor Parameters:
* hInst HINSTANCE of the application.
*/
CClient::CClient(HINSTANCE hInst)
: CWindow(hInst)
{
return;
}
CClient::~CClient(void)
{
return;
}
/*
* CClient::FInit
*
* Purpose:
* Creates a client area window sensitive to SDI or MDI (compile-time).
*
* Parameters:
* hMenuWindow HWND of the Window menu on the frame.
* pRect LPRECT containing the desired window rectangle.
* pFR LPCFrame to which this client belongs.
*
* Return Value:
* BOOL TRUE if the function succeeded, FALSE otherwise.
*/
BOOL CClient::FInit(HMENU hMenuWindow, LPRECT pRect, LPCFrame pFR)
{
HWND hWndFrame;
#ifdef MDI
CLIENTCREATESTRUCT ccs;
#endif
m_pFR=pFR;
hWndFrame=m_pFR->Window();
#ifdef MDI
ccs.hWindowMenu =hMenuWindow;
ccs.idFirstChild=ID_MDICHILDMIN;
//Create the MDI client filling the client area
m_hWnd=CreateWindow("mdiclient", "mdiclient"
, MDIS_ALLCHILDSTYLES | WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE
, pRect->left, pRect->top, pRect->right-pRect->left
, pRect->bottom-pRect->top, hWndFrame, NULL, m_hInst, (LPSTR)&ccs);
#else
//SDI case, create out own SDI Client window
m_hWnd=CreateWindow(SZCLASSSDICLIENT, SZCLASSSDICLIENT
, WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE, pRect->left, pRect->top
, pRect->right-pRect->left, pRect->bottom-pRect->top, hWndFrame
, NULL, m_hInst, 0L);
#endif
return (NULL!=m_hWnd);
}
/*
* CClient::CreateCDocument
*
* Purpose:
* Constructs a new document. This function is overridable so an
* app can use the default CClient but create a derived document class.
*
* Parameters:
* None
*
* Return Value:
* LPCDocument Pointer to the new document object.
*/
LPCDocument CClient::CreateCDocument(void)
{
return new CDocument(m_hInst);
}
/*
* CClient::TranslateAccelerator
*
* Purpose:
* Provides an isolated system accelerator translation as necessary
* for the client window. In MDI this calls TranslateMDISysAccel
* but is a NOP in SDI.
*
* Parameters:
* pMsg LPMSG to the message from GetMessage
*
* Return Value:
* BOOL TRUE if the accelerator was translated and processed,
* FALSE otherwise.
*/
BOOL CClient::TranslateAccelerator(LPMSG pMsg)
{
#ifdef MDI
return TranslateMDISysAccel(m_hWnd, pMsg);
#else
return FALSE;
#endif
}
/*
* CClient::DefFrameProc
*
* Purpose:
* Encapsulates which default message procedure to call for a frame window:
* SDI (DefWindowProc) or MDI (DefFrameProc).
*
* Parameters:
* hWnd HWND of the frame
* iMsg UINT of the message
* wParam WPARAM of the message
* lParam LPARAM of the message
*
* Return Value:
* LRESULT Return value for the message.
*/
LRESULT CClient::DefaultFrameProc(HWND hWnd, UINT iMsg, WPARAM wParam
, LPARAM lParam)
{
#ifdef MDI
return (DefFrameProc(hWnd, m_hWnd, iMsg, wParam, lParam));
#else
return (DefWindowProc(hWnd, iMsg, wParam, lParam));
#endif
}
/*
* CClient::OnWindowCommand
*
* Purpose:
* Handles Window menu commands for MDI situations. This is a NOP in SDI.
*
* Parameters:
* uCommand UINT command to execute:
* WM_MDICASCADE
* WM_MDITILE
* WM_MDIICONARRANGE
*
* uOption UINT optional parameter for WM_MDITILE, either
* MDITILE_HORIZONTAL or MDITILE_VERTICAL.
*
* Return Value:
* None
*/
void CClient::OnWindowCommand(UINT uCommand, UINT uOption)
{
SendMessage(m_hWnd, uCommand, (WPARAM)uOption, 0L);
return;
}
/*
* CClient::OnSize
*
* Purpose:
* Handles resizing the client window when the frame is resized.
*
* Parameters:
* x, y UINT new location of the window.
* cx, cy UINT new dimensions of the window.
*
* Return Value:
* None
*/
void CClient::OnSize(UINT x, UINT y, UINT cx, UINT cy)
{
SetWindowPos(m_hWnd, NULL, x, y, cx, cy, SWP_NOZORDER | SWP_NOACTIVATE);
return;
}
/*
* CClient::NewDocument
*
* Purpose:
* Creates a new blank document in the client space. See CloseDocument
* for the opposite effect.
*
* Parameters:
* fVisible BOOL indicating if the document is to be visible or not.
* pAdv LPCDocumentAdviseSink to set with the new document for
* notifications. Can be NULL.
*
* Return Value:
* LPCDocument Pointer to the new document object.
*/
LPCDocument CClient::NewDocument(BOOL fVisible, LPCDocumentAdviseSink pAdv)
{
MDICREATESTRUCT mcs;
HWND hWndDoc;
LPCDocument pDoc;
DOCUMENTINIT di;
BOOL fCreate=TRUE;
#ifdef MDI
//In MDI we create a new CDocument
pDoc=CreateCDocument(); //This could create a derived class...
#else
//In SDI we close the one we have and create a new one.
pDoc=ActiveDocument();
if (NULL!=pDoc)
CloseDocument(pDoc);
pDoc=CreateCDocument();
#endif
if (fCreate)
{
/*
* We implement this by having the client window actually create the
* windows instead of using the CDocument initializer. Reason being
* is that we ask the client to actually create the window using
* WM_MDICREATE (which works for our SDI client as well. Since we
* need to conditionally compile for MDI or SDI here, we create
* a window before calling the document constructor.
*/
mcs.szTitle="";
mcs.szClass=SZCLASSDOCUMENT;
mcs.hOwner =m_hInst;
mcs.lParam =(LPARAM)(LPSTR)pDoc;
mcs.x =CW_USEDEFAULT;
mcs.cx=CW_USEDEFAULT;
mcs.y =CW_USEDEFAULT;
mcs.cy=CW_USEDEFAULT;
/*
* Set the style of the window, controlling visiblity.
* WS_CLIPCHILDREN is important to prevent unnecessary flashing
* of document contents that we'll usually fill with some
* editor window.
*/
#ifdef MDI
mcs.style=WS_CHILD | WS_SYSMENU | WS_CAPTION | WS_CLIPSIBLINGS
| WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX
| WS_CLIPCHILDREN | ((fVisible) ? WS_VISIBLE : 0L);
#else
mcs.style=WS_CHILD | WS_CLIPCHILDREN | ((fVisible) ? WS_VISIBLE : 0L);
#endif
//Tell the Client window to create the child
hWndDoc=(HWND)(UINT)SendMessage(m_hWnd, WM_MDICREATE, 0
, (LONG)(LPMDICREATESTRUCT)&mcs);
di.idsMin=IDS_STANDARDDOCMIN;
di.idsMax=IDS_STANDARDDOCMAX;
di.hWndDoc=hWndDoc;
di.pAdv=pAdv;
if (!pDoc->FInit(&di))
{
SendMessage(m_hWnd, WM_MDIDESTROY, (WPARAM)hWndDoc, 0L);
delete pDoc;
return NULL;
}
}
m_cDoc++;
//Update menus and gizmos for the new document if visible
if (fVisible)
m_pFR->UpdateGizmos();
return pDoc;
}
/*
* CClient::ActiveDocument
*
* Purpose:
* Returns the active document window (encapsulates WM_MDIGETACTIVE)
*
* Parameters:
* None
*
* R